﻿using UtilZ.Dotnet.Ex.Log;

namespace UtilZ.Dotnet.AvaloniaDesktopEx
{
    /// <summary>
    /// 日志控件显示样式类
    /// </summary>
    public class LogShowStyle
    {
        /// <summary>
        /// 样式标识ID
        /// </summary>
        public int ID { get; private set; }

        /// <summary>
        /// 文本前景色Brush
        /// </summary>
        public Avalonia.Media.IBrush ForegroundBrush { get; private set; }

        /// <summary>
        /// 文本大小
        /// </summary>
        public double FontSize { get; private set; }

        /// <summary>
        /// 字体
        /// </summary>
        public string FontFamily { get; private set; }

        /// <summary>
        /// 样式名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 默认字体大小
        /// </summary>
        private const double defaultFontSize = 15d;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="id">样式标识ID</param>
        /// <param name="foregroundBrush">文本前景色Brush</param>
        /// <param name="fontFamily">文本字体[null使用默认字体]</param>
        /// <param name="fontSize">文本大小</param>
        public LogShowStyle(int id, Avalonia.Media.Brush foregroundBrush, string fontName, double fontSize)
        {
            if (fontSize <= 0)
            {
                throw new ArgumentException("字体大小值无效", nameof(fontSize));
            }

            if (string.IsNullOrWhiteSpace(fontName))
            {
                fontName = "Microsoft YaHei,Simsun,苹方-简,宋体-简";
            }

            this.ID = id;
            this.ForegroundBrush = foregroundBrush;
            this.FontFamily = fontName;
            this.FontSize = fontSize;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="id">样式标识ID</param>
        /// <param name="foreground">文本前景色</param>
        /// <param name="fontName">文本字体名称[null使用默认字体]</param>
        /// <param name="fontSize">文本大小</param>
        public LogShowStyle(int id, Avalonia.Media.Color foreground, string fontName = null, double fontSize = defaultFontSize) :
            this(id, new Avalonia.Media.SolidColorBrush(foreground), fontName, fontSize)
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="level">日志级别</param>
        /// <param name="foreground">文本前景色</param>
        /// <param name="fontName">文本字体名称[null使用默认字体]</param>
        /// <param name="fontSize">文本大小</param>
        public LogShowStyle(LogLevel level, Avalonia.Media.Color foreground, string fontName = null, double fontSize = defaultFontSize) :
            this((int)level, new Avalonia.Media.SolidColorBrush(foreground), fontName, fontSize)
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="id">样式标识ID</param>
        /// <param name="foreground">文本前景色</param>
        /// <param name="fontName">文本字体名称[null使用默认字体]</param>
        /// <param name="fontSize">文本大小</param>
        public LogShowStyle(int id, System.Drawing.Color foreground, string fontName = null, double fontSize = defaultFontSize) :
            this(id, new Avalonia.Media.SolidColorBrush(Avalonia.Media.Color.FromArgb(foreground.A, foreground.R, foreground.G, foreground.B)), fontName, fontSize)
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="level">日志级别</param>
        /// <param name="foreground">文本前景色</param>
        /// <param name="fontName">文本字体名称[null使用默认字体]</param>
        /// <param name="fontSize">文本大小</param>
        public LogShowStyle(LogLevel level, System.Drawing.Color foreground, string fontName = null, double fontSize = defaultFontSize) :
            this((int)level, new Avalonia.Media.SolidColorBrush(Avalonia.Media.Color.FromArgb(foreground.A, foreground.R, foreground.G, foreground.B)), fontName, fontSize)
        {

        }




    }
}